<template>
	<view class="page">
		<template v-if="isLogin">
			<view class="category-list row-2">
				<navigator url="/package_active/search-data/search-data" open-type="navigate" hover-class="none" class="item">
					<view class="icon"><image src="@/static/images/data_search.png" mode="widthFix"></image></view>
					<view class="text">数据查询</view>
				</navigator>
				<navigator url="/package_active/dataList/dataList" open-type="navigate" hover-class="none" class="item">
					<view class="icon"><image src="@/static/images/datas.png" mode="widthFix"></image></view>
					<view class="text">防控数据</view>
				</navigator> 
			</view>
			
			<view class="start-btn-area">
				<!-- 常规作业入口 -->
				<!-- <navigator url="/package_active/form/form" hover-class="none" class="btn"> 
					<image src="@/static/images/fk_start.png" mode="widthFix"></image>
				</navigator> -->
				
				<template >
					<view class="tab-bar">
						<view class="tab">
							<view :class="['item',{'active':type==1}]" @click="changeType(1)">投药旗扫码作业</view>
							<!-- <view :class="['item',{'active':type==2}]"  @click="changeType(2)">常规作业</view> -->
						</view>
					</view>
					
					
					<!-- 常规作业入口 -->
					<view v-if="type==2" class="btn" @click="goWork">
						<image src="@/static/images/fk_start.png" mode="widthFix"></image>
					</view>
					<!-- <navigator v-if="type==2" url="/package_active/form/form" hover-class="none" class="btn"> 
						<image src="@/static/images/fk_start.png" mode="widthFix"></image>
					</navigator> -->
					
					<!-- 扫码作业入口 -->
					<view v-if="type==1" class="btn" @click="scanCode"> 
						<image src="@/static/images/fk_scan_start.png" mode="widthFix"></image>
					</view>
					<view class="name"><text>红火蚁全民防控</text></view>
				</template>
			</view>
 
			 
		</template>
	</view>
</template>

<script>
	import {
		uniScanCode,getSystemInfo
	} from '@/common/promise.js'
	import {
		queryToJSON
	} from '@/common/util.js' 
	import {
		getCardTips,Hide
	} from '@/common/getCardTips.js' 
	
	
	
	
	export default {
		name: 'name',
		data() {
			return { 
				isLogin: false, 
				userInfo: uni.getStorageSync('userInfo'),
				loginStateUpdate: false,
				isCertificage:'',   // 1 获得资格，去填写信息  // -2 不满足资格，需学习实操   // 2 已获取证书
				app_name: getApp().globalData.app_name,
				type:1,
				isActive:false, 
			}


		},
		async onLoad() {			
			this.isLogin=await this.$loginState('check'); 
		},
		async onShow() { 			
			this.checkCertificate();			
		},
		onHide() {
			Hide();
		},
		onUnload() {
			Hide();
		},
		methods: {
			
			// 检测领证条件
			checkCertificate:async function(){
				let h_res=await this.$api.yfk_api.checkCertificate();    // 检测是否满足领取条件，1满足领取条件  
				if(h_res.data.ret==1){
					let res=await this.$api.yfk_api.certificateInfo();  
					if(res.data.ret==-1 || (res.data.ret==1&&(res.data.data.isaudit==0||res.data.data.isaudit==2))){    
						// -1 无证书  1 有证书 审核中 0 审核失败2 弹窗
						let system = await getSystemInfo(); //  获取系统信息 
						this.isActive=false;
						getCardTips({
							system:system
						}); 
					}else{
						this.isActive=true;
					}		
				}else{ 
					// 审核中 0 审核失败2 弹窗
					let system = await getSystemInfo(); //  获取系统信息
					this.isActive=false;
					getCardTips({
						system:system
					}); 
				}
			},
			 
			
			// 检测是否有领取证书资格（3条审核通过的数据）
			checkCertificate1:async function(){
				let h_res=await this.$api.yfk_api.certificateInfo(); 
				console.log(h_res)
				if(h_res.data.ret!=1){    
					// 审核中 0 审核失败2 弹窗
					let system = await getSystemInfo(); //  获取系统信息 
					setTimeout(()=>{
						getCardTips({
							system:system
						}); 
					},500) 
				}else{
					this.isActive=true;
				}				
			},
			
			changeType:function(type){
				this.type=type;
			},
			
			goWork:function(){ 
				uni.navigateTo({
					url:'/package_active/form/form'
				})
			},
			  
			 
			scanCode:async function(){ 
				
				if(!this.isActive){
					let system = await getSystemInfo(); //  获取系统信息
					setTimeout(()=>{
						getCardTips({
							system:system
						}); 
					},500) 
					return
				}
				  
				let res=await uniScanCode({ 
					scanType:['qrCode'],
					autoZoom:false
				}) 
				
				if(res.errMsg=="scanCode:ok"){
					
					let query=res.result.split('?')[1];					
					let query_data=queryToJSON(query); 
					uni.showLoading();
					let result=await this.$api.pro_api.qmfkScanResult({
						devnumber:query_data.devnumber,
						uuid:query_data.uuid 
					})    
					if(result.data.ret==1){
						uni.hideLoading();
						uni.navigateTo({
							url:`/package_active/form/form?type=scan&pro_id=${result.data.data.pro_id}&devnumber=${query_data.devnumber}&uuid=${query_data.uuid}`
						})
					}else if(result.data.ret==0){
						uni.hideLoading();
						uni.navigateTo({
							url:`/package_active/dataDetail/dataDetail?id=${result.data.data}`
						})
					}else{
						uni.hideLoading();
						uni.showToast({
							icon: "none",
							title: result.data.message, 
							 
						})
					} 
				} 
			}
		},
		components: {

		},

		computed: {

		},
		watch: {

		}

	}
</script>

<style lang="less" scoped> 
	.category-list{
		background: #fff;
		margin-bottom: 20rpx;
		padding: 20rpx 0 0;
		.item{
			.icon{
				width: 30%!important;
			}
		}
	}
	.name {
		text-align: center;

		text {
			padding-top: 10rpx;
			border-top: 2rpx dashed #999;
			font-size: 28rpx;
			color: #999;
		}
	}
	
	.tab-bar{
		position: absolute;
		left:0;
		top:0;
		width: 100%;
	}
	.tab{ 
		width: 80%;		
		margin: 0 auto;
		display: flex;
		justify-content: center;
		align-items: center;
		// border:1rpx solid #f00;
		border-radius: 10rpx;
		font-size: 32rpx;
		.item{
			width: 50%; 
			height: 82rpx;
			line-height: 82rpx;
			text-align: center;
			color:#666;
			background: #fff;
			border-radius: 10rpx;
		}
		.active{
			height: 82rpx;
			line-height: 82rpx;
			background: #f00;
			color:#fff;
			border-radius: 8rpx;
		}
	}
	
	.start-btn-area{
		position:absolute;
		left:0;
		bottom:0;
		width:100%;
		height: 70%; 
	}
	
	.get-code-popup {
		.phone-text {
			margin-bottom: 30rpx;
			color: #666;
		}
	
		.code-comfirm-btn {
			height: 70rpx;
			line-height: 70rpx;
			margin: 0 auto;
			background: linear-gradient(#e96b5c, #ce3c2f);
			border-radius: 8rpx;
			color: #fff;
			text-align: center;
			font-size: 30rpx;
		}
	}
	.code-bar {
		display: flex;
		height: 80rpx;
		border: 1rpx solid #eee;
		border-radius: 15rpx;
		margin-bottom: 40rpx;
	
		input {
			width: 90%;
			height: 80rpx;
			line-height: 80rpx;
			padding: 0 10rpx;
			font-size: 30rpx;
		}
	
		.get-code-btn {
			flex-shrink: 0;
			width: 35%;
			line-height: 80rpx;
			text-align: center;
			font-size: 30rpx;
			color: #09f;
		}
	}

	.btn {
		width: 60%;
		margin: 20% auto 0;  
		image {
			width: 100%;
		}
	}
	
	
</style>
